﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;

namespace FairyWorld.Models
{
    public class SampleData : DropCreateDatabaseIfModelChanges<SrcManager>
    {
        protected override void Seed(SrcManager context)
        {
            DateTime time = DateTime.Now;
            var users = new List<User>
            {
                new User { username = "peter", password = "peter", ConfirmPassword = "peter", email = "hjwdzh@gmail.com", phone = "18810305450", createTime = time.ToString(), iconUrl = @"../../Content/image/head/girlicon3.jpg",
                    fold = new Fold()
                    {
                        files = new List<MyFile>
                        {
                            new MyFile { tag = 1, filename = "小村之恋", url = "content/files/13_小村之恋.mp3", createTime = time.ToString(), size = 1024 * 607},
                            new MyFile { tag = 2, filename = "image1", url = "content/files/14_a.jpg", createTime = time.ToString(), size = 1024 * 276 },
                            new MyFile { tag = 3, filename = "doc1", url = "content/files/15_b.doc", createTime = time.ToString(), size = 1024 * 17 },
                            new MyFile { tag = 4, filename = "file1", url = "content/files/16_c.doc", createTime = time.ToString(), size = 1024 * 17  }
                        },
                        folds = new List<Fold>
                        {
                            new Fold()
                            {
                                foldname = "folder1_1",
                                files = new List<MyFile>
                                {
                                    new MyFile { tag = 1, filename = "在水一方", url = "content/files/1_在水一方.mp3", createTime = time.ToString(), size = 1024 * 2742 },
                                    new MyFile { tag = 2, filename = "image3", url = "content/files/2_a.jpg", createTime = time.ToString(), size = 1024 * 276 },
                                    new MyFile { tag = 3, filename = "doc3", url = "content/files/3_b.doc", createTime = time.ToString(), size = 1024 * 17 },
                                    new MyFile { tag = 4, filename = "file3", url = "content/files/4_c.doc", createTime = time.ToString(), size = 1024 * 17 }
                                }
                            },
                            new Fold()
                            {
                                foldname = "folder1_2",
                                files = new List<MyFile>
                                {
                                    new MyFile { tag = 1, filename = "南海姑娘", url = "content/files/9_南海姑娘.mp3", createTime = time.ToString(), size = 1024 * 2556 },
                                    new MyFile { tag = 2, filename = "image1", url = "content/files/10_a.jpg", createTime = time.ToString(), size = 1024 * 276 },
                                    new MyFile { tag = 3, filename = "doc1", url = "content/files/11_b.doc", createTime = time.ToString(), size = 1024 * 17 },
                                    new MyFile { tag = 4, filename = "file1", url = "content/files/12_c.doc", createTime = time.ToString(), size = 1024 * 17 }
                                },
                                folds = new List<Fold>
                                {
                                    new Fold()
                                    {
                                        foldname = "folder2_1",
                                        files = new List<MyFile>
                                        {
                                            new MyFile { tag = 1, filename = "我只在乎你", url = "content/files/5_我只在乎你.mp3", createTime = time.ToString(), size = 1024 * 4091 },
                                            new MyFile { tag = 2, filename = "image2", url = "content/files/6_a.jpg", createTime = time.ToString(), size = 1024 * 276 },
                                            new MyFile { tag = 3, filename = "doc2", url = "content/files/7_b.doc", createTime = time.ToString(), size = 1024 * 17 },
                                            new MyFile { tag = 4, filename = "file2", url = "content/files/8_c.doc", createTime = time.ToString(), size = 1024 * 17 }
                                        }
                                    }
                                },
                            }

                      },
                  }},
                new User { username = "chenlu", password = "chenlu", ConfirmPassword = "chenlu", email = "hjwdzh1@gmail.com", phone = "18810305450", fold = new Fold(), createTime = time.ToString(),iconUrl = @"../../Content/image/head/girlicon3.jpg"},
                new User { username = "wangxiaoyou", password = "wangxiaoyou", ConfirmPassword = "wangxiaoyou", email = "hjwdzh2@gmail.com", phone = "18810305450", fold = new Fold(), createTime = time.ToString(),iconUrl = @"../../Content/image/head/girlicon3.jpg"},
                new User { username = "peter1", password = "peter1", ConfirmPassword = "peter1", email = "hjwdzh3@gmail.com", phone = "18810305450", fold = new Fold(), createTime = time.ToString(),iconUrl = @"../../Content/image/head/girlicon3.jpg"},
                new User { username = "chenlu1", password = "chenlu1", ConfirmPassword = "chenlu1", email = "hjwdzh4@gmail.com", phone = "18810305450", fold = new Fold(), createTime = time.ToString(),iconUrl = @"../../Content/image/head/girlicon3.jpg"},
                new User { username = "wangxiaoyou1", password = "wangxiaoyou1", ConfirmPassword = "wangxiaoyou1", email = "hjwdzh5@gmail.com", phone = "18810305450", fold = new Fold(), createTime = time.ToString(),iconUrl = @"../../Content/image/head/girlicon3.jpg"},
                new User { username = "peter2", password = "peter2", ConfirmPassword = "peter2", email = "hjwdzh6@gmail.com", phone = "18810305450", fold = new Fold(), createTime = time.ToString(),iconUrl = @"../../Content/image/head/girlicon3.jpg"},
                new User { username = "chenlu2", password = "chenlu2", ConfirmPassword = "chenlu2", email = "hjwdzh7@gmail.com", phone = "18810305450", fold = new Fold(), createTime = time.ToString(),iconUrl = @"../../Content/image/head/girlicon3.jpg"},
                new User { username = "wangxiaoyou2", password = "wangxiaoyou2", ConfirmPassword = "wangxiaoyou2", email = "hjwdzh8@gmail.com", phone = "18810305450", fold = new Fold(), createTime = time.ToString(),iconUrl = @"../../Content/image/head/girlicon3.jpg"},
            };
            var groups = new List<Group>
            {
                new Group { groupname = "fire",
                    creator = users.Single(u => u.username == "wangxiaoyou"),
                    introduction = "This group is about fire!",
                    createTime = time.ToString(),
                    fold = new Fold()
                    {
                        files = new List<MyFile>
                        {
                            new MyFile { tag = 1, filename = "小村之恋", url = "content/files/13_小村之恋.mp3", createTime = time.ToString(), creator = users[0], size = 1024 * 607},
                            new MyFile { tag = 2, filename = "image1", url = "content/files/14_a.jpg", createTime = time.ToString(), creator = users[0], size = 1024 * 276 },
                            new MyFile { tag = 3, filename = "doc1", url = "content/files/15_b.doc", createTime = time.ToString(), creator = users[0], size = 1024 * 17 },
                            new MyFile { tag = 4, filename = "file1", url = "content/files/16_c.doc", createTime = time.ToString(), creator = users[0], size = 1024 * 17 }
                        },
                        folds = new List<Fold>
                        {
                            new Fold()
                            {
                                foldname = "folder1_1",
                                files = new List<MyFile>
                                {
                                    new MyFile { tag = 1, filename = "在水一方", url = "content/files/1_在水一方.mp3", creator = users[0], createTime = time.ToString(), size = 1024 * 2742 },
                                    new MyFile { tag = 2, filename = "image3", url = "content/files/2_a.jpg", creator = users[0], createTime = time.ToString(), size = 1024 * 276 },
                                    new MyFile { tag = 3, filename = "doc3", url = "content/files/3_b.doc", creator = users[0], createTime = time.ToString(), size = 1024 * 17 },
                                    new MyFile { tag = 4, filename = "file3", url = "content/files/4_c.doc", creator = users[0], createTime = time.ToString(), size = 1024 * 17 }
                                }
                            },
                            new Fold()
                            {
                                foldname = "folder1_2",
                                files = new List<MyFile>
                                {
                                    new MyFile { tag = 1, filename = "南海姑娘", url = "content/files/9_南海姑娘.mp3", creator = users[0], createTime = time.ToString(), size = 1024 * 2556},
                                    new MyFile { tag = 2, filename = "image1", url = "content/files/10_a.jpg", creator = users[0], createTime = time.ToString(), size = 1024 * 276 },
                                    new MyFile { tag = 3, filename = "doc1", url = "content/files/11_b.doc", creator = users[0], createTime = time.ToString(), size = 1024 * 17 },
                                    new MyFile { tag = 4, filename = "file1", url = "content/files/12_c.doc", creator = users[0], createTime = time.ToString(), size = 1024 * 17 }
                                },
                                folds = new List<Fold>
                                {
                                    new Fold()
                                    {
                                        foldname = "folder2_1",
                                        files = new List<MyFile>
                                        {
                                            new MyFile { tag = 1, filename = "我只在乎你", url = "content/files/5_我只在乎你.mp3", creator = users[0], createTime = time.ToString(), size = 1024 * 4091 },
                                            new MyFile { tag = 2, filename = "image2", url = "content/files/6_a.jpg", creator = users[0], createTime = time.ToString(), size = 1024 * 276 },
                                            new MyFile { tag = 3, filename = "doc2", url = "content/files/7_b.doc", creator = users[0], createTime = time.ToString(), size = 1024 * 17 },
                                            new MyFile { tag = 4, filename = "file2", url = "content/files/8_c.doc", creator = users[0], createTime = time.ToString(), size = 1024 * 17 }
                                        }
                                    }
                                },
                            }

                      },
                  }},
                new Group { introduction = "This group is about water!", createTime = time.ToString(), groupname = "water", fold = new Fold(),
                creator = users.Single(u => u.username == "wangxiaoyou1")},
                new Group { groupname = "cloud", fold = new Fold(), introduction = "This group is about fire!", createTime = time.ToString(),
                creator = users.Single(u => u.username == "wangxiaoyou2")},
            };

            new List<Role>
            {
                new Role { group = groups.Single(g => g.groupname == "fire"), power = 0, user = users.Single(u => u.username == "peter")},
                new Role { group = groups.Single(g => g.groupname == "water"), power = 0, user = users.Single(u => u.username == "peter")},
                new Role { group = groups.Single(g => g.groupname == "fire"), power = 1, user = users.Single(u => u.username == "chenlu")},
                new Role { group = groups.Single(g => g.groupname == "fire"), power = 2, user = users.Single(u => u.username == "wangxiaoyou")},
                new Role { group = groups.Single(g => g.groupname == "water"), power = 1, user = users.Single(u => u.username == "wangxiaoyou")},
                new Role { group = groups.Single(g => g.groupname == "water"), power = 0, user = users.Single(u => u.username == "peter1")},
                new Role { group = groups.Single(g => g.groupname == "water"), power = 1, user = users.Single(u => u.username == "chenlu1")},
                new Role { group = groups.Single(g => g.groupname == "water"), power = 2, user = users.Single(u => u.username == "wangxiaoyou1")},
                new Role { group = groups.Single(g => g.groupname == "cloud"), power = 0, user = users.Single(u => u.username == "peter2")},
                new Role { group = groups.Single(g => g.groupname == "cloud"), power = 1, user = users.Single(u => u.username == "chenlu2")},
                new Role { group = groups.Single(g => g.groupname == "cloud"), power = 2, user = users.Single(u => u.username == "wangxiaoyou2")}
            }.ForEach(a => context.roles.Add(a));
        }
    }
}